import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    isHome: "",
    isSearch: "",
    isCar: "",
    urlStr: "home",
    carNum: 0,
    commentId: ""
  },
  mutations: {
    getUrlStr(state, urlStr) {
      state.urlStr = urlStr.substring(1);
      state.isHome = urlStr === "/home";
      state.isSearch = urlStr === "/search";
      state.isCar = urlStr === "/car";
    },
    getCarNum(state) {
      let session =
        window.sessionStorage.getItem("car") == null ||
        window.sessionStorage.getItem("car") == ""
          ? 0
          : JSON.parse(window.sessionStorage.getItem("car"));
      // console.log(session);
      if (session == 0) return;
      state.carNum = 0;
      session.forEach(item => {
        state.carNum += item.count;
      });
    },
    changeCommentId(state, id) {
      state.commentId = id;
    }
  },
  actions: {},
  modules: {}
});
